from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SPUSpecification, SPU
from meiduo_admin.serialziers.specs import SPUSpecificationSerializer, SPUSerializer
from meiduo_admin.utils.page import PageNum


class SpecsView(ModelViewSet):
    """
    商品规格CRUD
    """
    serializer_class = SPUSpecificationSerializer
    queryset = SPUSpecification.objects.all()
    pagination_class = PageNum

    def simple(self, request):
        """
        获取spu 商品
        :param request:
        :return:
        """
        spus = SPU.objects.all()
        ser = SPUSerializer(spus, many=True)
        return Response(ser.data)

    # def destroy(self, request, *args, **kwargs):
        """
        实现逻辑删除
        """
    #     instance = self.get_object()
    #     instance.is_delete = True
    #     instance.save()
    #     # self.perform_destroy(instance)
    #     # return Response(status=status.HTTP_204_NO_CONTENT)
